<!DOCTYPE html>
<!--[if IE 8 ]><html class="ie8"><![endif]-->
<!--[if IE 9 ]><html class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html class="w3c"><!--<![endif]-->
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {load href="__STATIC__/layui/css/layui.css"/}
    {load href="__CSS__/bootstrap.min.css"/}
    {load href="__CSS__/elpis.min.css"/}
    {load href="__STATIC__/layui/layui.all.js"/}
    {load href="__STATIC__/font-awesome/css/font-awesome.min.css"/}
    {load href="__JS__/jquery-1.10.2.min.js"/}
    {load href="__JS__/bootstrap.bundle.min.js"/}
    <link href="__STATIC__/icheck/skins/square/square.css" rel="stylesheet">
    <script src="__STATIC__/icheck/icheck.min.js"></script>
    <script src="__JS__/js.cookie.min.js"></script>

    <title>后台管理</title>
    {block name="style"}{/block}
    <script>
        var APP = '';
        var ROOT = '';
        var PUBLIC = '/public';
    </script>
    <style>
        .nav-menu{
            display:none;
        }
        .nav-menu li .sub-menu {
            display:block;
        }
    </style>
</head>
<body class="layout-body">

<div class="app-header">
    <div class="container-fluid">
        <div class="logo"><img src="__IMG__/logo.png" alt=""></div>
        <ul class="nav navbar-toolbar nav-tabs main-nav">
            {volist name="all_menu_list" id="r"}
            <li>
                <a class="nav-link" id="top_{$r.id}" href="javascript:;">
                <i class="{$r['icon']}"></i>
                <span>{$r['title']}</span>
                </a>
            </li>
            {/volist}
        </ul>
        <ul class="navbar-top-links float-right">
            {if condition="count($Lang)>1"}
            <li>
                <a class="dropdown-toggle" id="lang_flag" href="#" data-toggle="dropdown">
                    <img style="margin:0 5px;height: 20px;" src="__PUBLIC__/images/flag/{$Think.session.lang.flag}"/><span>{$Think.session.lang.name}</span>
                </a>
                <div class="dropdown-menu dropdown-menu-right">
                    {volist name="Lang" id="r"}
                    <a class="dropdown-item js_change_lang" href="javascript:void(0);" data-url="{:U('Index/index', ['l'=>$r['mark']])}">
                        <img style="margin:0 5px;height: 20px;" src="__PUBLIC__/images/flag/{$r['flag']}"/>
                        <span>{$r['name']}</span>
                    </a>
                    {/volist}
                </div>
            </li>
            {/if}
            <li><a href="javascript:void(0);" data-href="{:U('Public/cache')}" class="js_update_cache" title="更新缓存"><i class="fa fa-lg fa-refresh"></i></a></li>
            <li><a href="/" target="_blank" title="浏览站点"><i class="fa fa-lg fa-globe"></i></a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <img src="{empty name="Think.session.admin.avatar"}__PUBLIC__/images/admin_avtar.jpg{else/}{$Think.session.admin.avatar|thumb=###,'30,30'}{/empty}" alt="avatar" style="max-width:30px;">
                    {$Think.session.admin.username}
                </a>
                <div class="dropdown-menu dropdown-menu-right">
                    <a class="dropdown-item" id="logout"  href="{:U('Login/logout')}"><i class="fa fa-sign-out"></i>安全退出</a>
                </div>
            </li>
        </ul>
    </div>
</div>
<!--侧边导航-->
<div class="app-side">
{volist name="all_menu_list" id="sub_menu"}
    <ul class="nav-menu" id="aside_{$sub_menu.id}">
        {volist name="sub_menu['_child']" id="r" key="ii"}
        <li>
            <a {empty name="r['_child']"}class="js_set_url"{/empty} data-title="{$r['title']}" data-href="{:U($r['name'])}" href="javascript:void(0);">
            <i class="{$r['icon']}"></i>
            <span>{$r['title']}</span>
            </a>
            {notempty name="r['_child']"}
            <ul class="sub-menu">
                {volist name="r._child" id="rr"}
                <li>
                    <a class="js_set_url" data-title="{$rr['title']}" data-href="{:U($rr['name'])}" href="javascript:void(0);">
                        <i class="{$rr['icon']}"></i><span>{$rr['title']}</span>
                    </a>
                </li>
                {/volist}
            </ul>
            {/notempty}
        </li>
        {/volist}
    </ul>
{/volist}
</div>

<div class="app-body">
    <nav>
        <!-- 面包屑导航 -->
        <ol class="breadcrumb">
            {volist name="parent_menu" id="menu_li" key="k"}
            <li class="breadcrumb-item">{eq name="k" value="1"}<i class="fa fa-map-marker"></i>{/eq}  {$menu_li.title}</li>
            {/volist}
        </ol>
    </nav>
    <div class="page">
        <div class="wrapper">
            {block name="main"}{/block}
        </div>  
    </div>
</div>


<!-- 引入js -->
{load href="__STATIC__/layer/layer.js"/}
{load href="__JS__/admin.js"/}
{load href="__JS__/jquery.form.min.js"/}

<!-- custom scrollbar plugin -->
<script type="text/javascript">
    if (!Cookies.get('id')) {
        var id = $('.main-nav a').eq(0).attr('id').split('_');
        $('#top_' + id[1]).addClass('active');
        $('#aside_' + id[1]).show();
        Cookies.set('id', id[1]);
    }
    $('.js_set_url').click(function(){
        var url = $(this).attr('data-href');
        window.location.href = url;
        return false;
    });

    $('.js_change_lang').click(function () {
        var url = $(this).data('url');
       
        window.location.href = url;
        return false;
    });

    $('.main-nav a').click(function(){
        var id = $(this).attr('id').split('_');
        $('.main-nav a').removeClass('active');
        $(this).parent().addClass('active');
        $('.nav-menu').hide();
        $('#aside_'+id[1]).show();

        var url = $('#aside_'+id[1]).find('.js_set_url').eq(0).attr('data-href');

        console.log(id);
        console.log(url);
        window.location.href = url;
        Cookies.set('id', id[1]);
        return false;
    });

    $('#top_' + Cookies.get('id')).addClass('active');
    $('#aside_' + Cookies.get('id')).show();

    $('.ajax_form_edit').click(function () {

        $(this).parents('form').ajaxForm({
            success: complete,  // post-submit callback
            dataType: 'json'
        });

        function complete(data) {
            if (data.status === 1) {
                layer.msg(data.info, {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    window.location.href = data.url;
                    return true;
                });
            } else {
                layer.msg(data.info, {
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        }
    });

    $('.ajax_form_add').click(function () {

        $(this).parents('form').ajaxForm({
            success: complete,  // post-submit callback
            dataType: 'json'
        });

        function complete(data) {
            if (data.status === 1) {
                layer.confirm(data.info, {
                    icon: 1,
                    btn: ['继续添加', '返回列表'] //按钮
                }, function () {
                    window.location.reload();
                    return false;
                }, function () {
                    window.location.href = data.url;
                    return true;
                });

            } else {
                layer.msg(data.info, {
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        }
    });


    //登出
    $('#logout').click(function(){
        var url = $(this).attr('href');
        $.ajax({
            url: url,
            success:function(data){
                Cookies.remove('id');
                layer.msg(data.info);
                window.location.href = "{:U('Login/index')}";
            }
        });
        return false;
    });

    //更新缓存
    $('.js_update_cache').click(function () {
        var url = $(this).attr('data-href');
        $.ajax({
            url: url,
            beforeSend:function(){
                layer.msg('正在更新缓存');
            },
            success:function(data){
                window.location.reload();
            }
        });
    });

    $(document).ready(function(){
        $('input').iCheck({
            checkboxClass: 'icheckbox_square',
            radioClass: 'iradio_square',
            increaseArea: '20%' // optional
        });
    });
</script>
{block name="script"}{/block}
</body>
</html>